import request from '@/utils/request'

const api_name = '/oj/problem'

export default {
  // 新增试题/草稿
  createProblem(problemAdd) {
    return request({
      url: `${api_name}`,
      method: 'post',
      data: problemAdd
    })
  },
  // 更新试题/草稿
  updateProblem(problemAdd) {
    return request({
      url: `${api_name}`,
      method: 'put',
      data: problemAdd
    })
  },
  // 根据ID获取试题信息
  getProblemInfo(problemID) {
    return request({
      url: `${api_name}/get/${problemID}`,
      method: 'get'
    })
  },
  // 分页获取本人试题
  getProblemList(problemPageRequest) {
    return request({
      url: `${api_name}/list`,
      method: 'post',
      data: problemPageRequest
    })
  },
  // 获取所有试题
  getAllProblems(problemPageRequest) {
    return request({
      url: `${api_name}/all`,
      method: 'post',
      data: problemPageRequest
    })
  },
  // 根据ID删除试题
  deleteProblem(problemID) {
    return request({
      url: `${api_name}/${problemID}`,
      method: 'delete'
    })
  },
  // 从回收站回收试题至草稿箱
  recycle(problemID) {
    return request({
      url: `${api_name}/recycle/${problemID}`,
      method: 'post'
    })
  },
  // 随机一题，返回随机试题的ID
  getRandomProblem() {
    return request({
      url: `${api_name}/random`,
      method: 'get'
    })
  },
  // 提交测评（执行代码）
  testCode(problemJudgeRequest) {
    return request({
      url: `${api_name}/test`,
      method: 'post',
      data: problemJudgeRequest
    })
  },
  // 提交测评
  judgeCode(problemJudgeRequest) {
    return request({
      url: `${api_name}/judge`,
      method: 'post',
      data: problemJudgeRequest
    })
  }
}
